import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import { defineConfig } from "vite";
import { viteTinyfy } from "vite-plugin-tinyfy";

const NODE_ENV = process.env.NODE_ENV;
const isProd = NODE_ENV === "prod";

// https://vitejs.dev/config/
export default defineConfig({
  server: {
    open: true,
    host: true,
    port: 4000,
    proxy: {
      "/pro-api": {
        target: `https://${NODE_ENV}-mobile-api.bankneo.co.id`,
        rewrite: (path: string) => path.replace(/^\/pro-api/, ""),
        changeOrigin: true,
        secure: false,
      },
    },
  },
  resolve: {
    alias: {
      "@": resolve(__dirname, "./src"),
    },
  },
  plugins: [vue(), viteTinyfy()],
  build: {
    minify: isProd,
    sourcemap: !isProd,
    rollupOptions: {
      output: {
        manualChunks: {
          vue: ["vue"],
          vueRouter: ["vue-router"],
          axios: ["axios"],
          i18n: ["i18n-use"],
          jsCookie: ["js-cookie"],
        },
      },
    },
  },
  optimizeDeps: {
    include: ["vue", "vue-router", "js-cookie", "i18n-use", "axios"],
  },
});
